package com.wfm.threadpooltaskexecutor;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Data
public class TaskTest {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Async
    public void execAsync() {
        log.info("异步开始： begin");
        try {
            Thread.sleep(1000);
            log.info("异步结束：finish");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public void execSync() {
        log.info("同步开始：sync");
        try {
            Thread.sleep(1000);
            log.info("同步结束：sync");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
